#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/3/8 17:05
# @Author  : jeff
# @FileName: db_config
from urllib import parse
from flask import Flask
from src.utils.read_config import db_config

host_name, port, username, password, database = db_config()

HOSTNAME = host_name
PORT = port
USERNAME = username
PASSWORD = password
DATABASE = database
pwd = parse.quote_plus(PASSWORD)


def config(app: Flask) -> Flask:
    app.config[
        'SQLALCHEMY_DATABASE_URI'] = f"mysql+pymysql://{USERNAME}:{pwd}@{HOSTNAME}:{PORT}/{DATABASE}?charset=utf8mb4"
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['SQLALCHEMY_ECHO'] = True
    return app
